﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataModel;
using SchoolBusiness;

namespace SchoolAdministration
{
    public partial class ManageUsers : System.Web.UI.Page
    {
        private readonly UserAccount _dm = new UserAccount();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                loadUserList();
            }

        }
        public void loadUserList()
        {
            List<UserData> users = new List<UserData>();
            users = _dm.ViewUsers();
            ViewUser.DataSource = users;
            ViewUser.DataBind();

        }
        protected void ViewUser_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                LinkButton l = (LinkButton)e.Row.FindControl("DeleteButton");

                l.Attributes.Add("onclick", "javascript:return " +
                     "confirm('Are you sure you want to delete this record ? " +
                     DataBinder.Eval(e.Row.DataItem, "Id") + "')");

            }
        }
        protected void ViewUser_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridViewRow row = ViewUser.SelectedRow;
        }

        protected void ViewUser_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Delete")
            {
                int id = Convert.ToInt32(e.CommandArgument);
                _dm.DeleteUserbyUserId(id);
                loadUserList();
            }
        }

        protected void ViewUser_RowDeleted(object sender, GridViewDeletedEventArgs e)
        {

        }

        protected void ViewUser_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {

        }
    }
}